﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity.ModelConfiguration;
using CodeFarmer.Model.Entities;

namespace CodeFarmer.Model.Mapping
{
    public class UserMap : EntityTypeConfiguration<User>
    {
        public UserMap()
        {
            this.HasKey(t => t.ID);

            this.Property(t => t.UserName)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.NickName)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.PassWord)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.PhotoUrl)
                .HasMaxLength(500);

            this.Property(t => t.Email)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.CreateTime)
                .IsRequired();

            this.Property(t => t.LastLoginIP)
                .HasMaxLength(50);

            this.Property(t => t.LastLoginTime)
                .IsRequired();

            this.Property(t => t.State)
                .IsRequired();

            this.ToTable("User");
            this.Property(t => t.UserName).HasColumnName("UserName");
            this.Property(t => t.NickName).HasColumnName("NickName");
            this.Property(t => t.PassWord).HasColumnName("PassWord");
            this.Property(t => t.PhotoUrl).HasColumnName("PhotoUrl");
            this.Property(t => t.Email).HasColumnName("Email");
            this.Property(t => t.CreateTime).HasColumnName("CreateTime");
            this.Property(t => t.LastLoginIP).HasColumnName("LastLoginIP");
            this.Property(t => t.LastLoginTime).HasColumnName("LastLoginTime");
            this.Property(t => t.State).HasColumnName("State");

            this.HasMany(t => t.Articles).WithRequired(t => t.Author);
        }
    }
}
